﻿using IM.Easy.Infrastructure.Query;
using IM.Easy.SystemServices.Dtos.Role;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.SystemServices.Dtos.User
{
    public class UserQueryDto : QueryBase
    {
        /// <summary>
        /// 昵称
        /// </summary>
        public string NickName { get; set; }

        /// <summary>
        /// 用户名称
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 手机号
        /// </summary>
        public string Mobile { get; set; }

        /// <summary>
        /// 组织部门ID
        /// </summary>
        public long DeptId { get; set; }

        /// <summary>
        /// 是否包含子部门用户
        /// </summary>
        public bool LeafDept { get; set; } = true;

        /// <summary>
        /// 用户状态
        /// </summary>
        public bool? IsActive { get; set; }

    }



    public class UserDto
    {
        public long Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [Required(ErrorMessage = "用户名不能为空")]
        public string UserName { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        public string NickName { get; set; }

        /// <summary>
        /// 真实姓名
        /// </summary>
        public string RealName { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        public string Mobile { get; set; }

        /// <summary>
        /// 电子邮件
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public int Gender { get; set; }


        /// <summary>
        /// 用户头像
        /// </summary>
        public string Avatar { get; set; }

        /// <summary>
        /// 部门ID
        /// </summary>
        public long? DeptId { get; set; }

        /// <summary>
        /// 创建方式
        /// </summary>
        public string CreationSource { get; set; }

        /// <summary>
        /// 用户状态
        /// </summary>
        public bool IsActive { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedAt { get; set; }

        ///// <summary>
        ///// 是否锁定
        ///// </summary>
        //public bool IsLocked { get; set; }

        //public DateTime? CreatedAt { get; set; }
    }

    /// <summary>
    /// 创建编辑用户请求体
    /// </summary>
    public class UserCreateDto
    {
        public long Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [Required(ErrorMessage = "用户名不能为空")]
        public string UserName { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        public string NickName { get; set; }

        /// <summary>
        /// 真实姓名
        /// </summary>
        public string RealName { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        public string Mobile { get; set; }

        /// <summary>
        /// 电子邮件
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public int Gender { get; set; }


        /// <summary>
        /// 用户头像
        /// </summary>
        public string Avatar { get; set; }

        /// <summary>
        /// 部门ID
        /// </summary>
        public long? DeptId { get; set; }

        /// <summary>
        /// 岗位ID
        /// </summary>
        public long? PostId { get; set; }


        /// <summary>
        /// 创建方式
        /// </summary>
        public string CreationSource { get; set; }

        /// <summary>
        /// 是否开通 本地邮箱
        /// </summary>
        public bool LocalEmail { get; set; }

        /// <summary>
        /// 用户状态
        /// </summary>
        public bool IsActive { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedAt { get; set; }

        /// <summary>
        /// 角色id
        /// </summary>
        public virtual long[] RoleIds { get; set; }
    }

    public class UserResponseDto : UserCreateDto
    {
        /// <summary>
        /// 超管标识
        /// </summary>
        public bool IsSuperAdmin
        {
            get
            {
                return Id == 1;
            }
        }

        public List<SysRoleDto> Roles { get; set; }


        public override long[] RoleIds
        {
            get
            {
                return Roles.Select(s => s.Id).ToArray();
            }

        }
    }
}
